﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using WP7Client.Helpers;
using WP7Client.Controller;
using System.Windows.Data;
using WP7Client.Classes;

namespace WP7Client.UserInterface.Pages
{
    public partial class WebBrowserSocialNetworkPage : MSHPhoneApplicationPage
    {
        public static readonly DependencyProperty URLProperty = DependencyProperty.Register("URL", typeof(String), typeof(WebBrowserSocialNetworkPage), null);
        public static readonly DependencyProperty NavigatedToURLProperty = DependencyProperty.Register("NavigatedToURL", typeof(String), typeof(WebBrowserSocialNetworkPage), null);

        public WebBrowserSocialNetworkPage()
        {
            InitializeComponent();

            Binding binding = new Binding("CurrentPageURL");
            SetBinding(WebBrowserSocialNetworkPage.URLProperty, binding);
            binding = new Binding("LastCheckedURL");
            binding.Mode = BindingMode.TwoWay;
            SetBinding(WebBrowserSocialNetworkPage.NavigatedToURLProperty, binding);
            DataContext = ControllerHelper.WebBrowserSocialNetworkController;
            theBrowser.IsScriptEnabled = true;
        }

        public String URL
        {
            get { return (String)GetValue(URLProperty); }
            set 
            { 
                SetValue(URLProperty, value);
                theBrowser.Navigate(new Uri(value));
            }
        }

        public String NavigatedToURL
        {
            get { return (String)GetValue(NavigatedToURLProperty); }
            set { SetValue(NavigatedToURLProperty, value); }
        }

        private void WebBrowserPage_Loaded(object sender, RoutedEventArgs e)
        {
            theBrowser.Navigate(new Uri(URL));
        }

        private void theBrowser_Navigating(object sender, NavigatingEventArgs e)
        {
            NavigatedToURL = e.Uri.ToString();
        }
    }
}